<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "https://raw.githubusercontent.com/rbatis/rbatis/master/rbatis-codegen/mybatis-3-mapper.dtd">
<mapper>
    <select id="get_user_page">
        `select su.* from sys_user su inner join sys_dept sd on su.dept_id = sd.dept_id`
        <where>
            `1 = 1`
            <if test="user_name != ''">
                ` and su.user_name like concat('%', #{user_name}, '%')`
            </if>
            <if test="phone_number != ''">
                ` and su.phonenumber like concat('%', #{phone_number}, '%')`
            </if>
            <if test="status != ''">
                ` and su.status = #{status}`
            </if>
            <if test="begin_time != ''">
                ` and su.create_time between #{begin_time} and #{end_time}`
            </if>
            <if test="dept_id != null">
                ` AND (su.dept_id = #{dept_id} OR su.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{dept_id}, ancestors) ))`
            </if>
            ` and su.del_flag = 0`
            ` limit #{page_num},#{page_size}`
        </where>
    </select>
    <select id="get_user_count">
        `select count(*) from sys_user su inner join sys_dept sd on su.dept_id = sd.dept_id`
        <where>
            `1 = 1`
            <if test="user_name != ''">
                ` and su.user_name = #{user_name}`
            </if>
            <if test="phonenumber != ''">
                ` and su.phonenumber = #{phone_number}`
            </if>
            <if test="status != ''">
                ` and su.status = #{status}`
            </if>
            <if test="begin_time != ''">
                ` and su.create_time between #{begin_time} and #{end_time}`
            </if>
            <if test="dept_id != null">
                ` AND (su.dept_id = #{dept_id} OR su.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{dept_id}, ancestors) ))`
            </if>
            ` and su.del_flag = 0`
        </where>
    </select>
    <select id="get_user_by_id">
        `select * from sys_user`
        <where>
            `user_id = #{user_id}`
        </where>
    </select>
    <update id="update_user_status_by_id">
        `update sys_user set status = #{status} where user_id = #{user_id}`
    </update>
</mapper>